import { GCellRenderer } from "../../../../com/mui/controls/GCellRenderer";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../resource/ImagesConst";
import { ObjCreate } from "../common/ObjCreate";
import { BaseItem } from "../common/BaseItem";
import { Language } from "../../../../extend/language/Language";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { ResFileConst } from "../../resource/ResFileConst";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { InvestmentConfig } from "../../resource/InvestmentConfig";
import { Cache } from "../../cache/Cache";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { ItemData } from "../../resource/info/ItemData";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { GButton } from "../../../../com/mui/controls/GButton";
import { TInvestPlan } from "../../../../Message/Db/Tables/TInvestPlan";
import { GTextFiled } from "../../../../com/mui/controls/GTextFiled";
type int = number;
//class InvestmentPlanPreviewCellRender
    
    export  class InvestmentPlanPreviewCellRender extends GCellRenderer
    {
        constructor()
        {
            super();
            return;
        }

        protected /* override */ configUI(): void
        {
            super.configUI();
            this._bg = new Object /* flash.display.Bitmap */();
            this.addChild(this._bg);
            this._nameTxtBmp = new Object /* flash.display.Bitmap */();
            this.addChild(this._nameTxtBmp);
            this._nameTxtBmp.x = 31;
            this._nameTxtBmp.y = 6;
            this._propBg = GlobalClass.getBitmap(ImagesConst.PropBg);
            this.addChild(this._propBg);
            this._propBg.x = 40;
            this._propBg.y = 39;
            this._expectionBmp = new Object /* flash.display.Bitmap */();
            this.addChild(this._expectionBmp);
            this._expectionBmp.x = 53;
            this._expectionBmp.y = 50;
            this._adTxt = ObjCreate.createGTextField("", 11, 107, 130, 50, this, new Object /* flash.text.TextFormat */(null, 12, 0, null, null, null, null, null, "center"));
            this._adTxt.multiline = true;
            this._adTxt.wordWrap = true;
            ObjCreate.createBg(3, 148, 140, 1, this, ImagesConst.SplitLine);
            this._propItem = new BaseItem();
            this.addChild(this._propItem);
            this._propItem.isDragAble = false;
            this._investBtn = ObjCreate.createGButton(Language.getString(90802), 40, 156, 65, 28, this, "ButtonRed");
            this._investBtn.drawNow();
            this._investBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onClick);
            LoaderHelp.addResCallBack(ResFileConst.investPlan, this.onLoaded);
            return;
        }

        /* internal  */onLoaded(): void
        {
            this._isLoaded = true;
            this._bg.bitmapData = GlobalClass.getBitmapData(ImagesConst.investCategoryBg);
            this._expectionBmp.bitmapData = GlobalClass.getBitmapData(ImagesConst.investExpection);
            this.setNameBmp();
            return;
        }

        /* internal  */setNameBmp(): void
        {
            var loc1=null;
            if (this._info && this._isLoaded) 
            {
                loc1 = "investCate_name_" + this._info.category;
                this._nameTxtBmp.bitmapData = GlobalClass.getBitmapData(loc1);
            }
            return;
        }

        protected onClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._info) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.InvestProject, this._info.id));
            }
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            var loc1=null;
            var loc2=0;
            var loc3=null;
            var loc4=null;
            if (arg1 == null) 
            {
                return;
            }
            super.data = arg1;
            if (arg1.data as int > 0) 
            {
                this._expectionBmp.visible = false;
                this._investBtn.visible = true;
                this._info = InvestmentConfig.instance.getInfoById(arg1.data);
                if (this._info) 
                {
                    this.setNameBmp();
                    if (Cache.instance.investment.getInvestedInfoById(this._info.id)) 
                    {
                        this._investBtn.enabled = false;
                        this._investBtn.filters = [FilterConst.colorFilter2];
                    }
                    else 
                    {
                        this._investBtn.enabled = true;
                        this._investBtn.filters = [];
                    }
                    this._propItem.itemData = new ItemData(this._info.itemCode);
                    this._propItem.drawNow();
                    this._propItem.amount = -1;
                    this._propItem.setSize(60, 60);
                    this._propItem.move(this._propBg.x + 5, this._propBg.y + 5);
                    loc1 = HTMLUtil.addColor(this._info.goldPay.toString(), GlobalStyle.color6);
                    loc2 = InvestmentConfig.instance.getIncomeByInfo(this._info);
                    loc3 = "<br>" + HTMLUtil.addColor(this._propItem.itemData.name + "x" + loc2, GlobalStyle.color6);
                    loc4 = Language.getStringByParam(90803, loc1, loc3);
                    this._adTxt.htmlText = loc4;
                }
            }
            else 
            {
                this._expectionBmp.visible = true;
                this._investBtn.visible = false;
            }
            return;
        }

        public /* override */ dispose(arg1: Boolean=true): void
        {
            super.dispose(arg1);
            this._expectionBmp = null;
            this._bg = null;
            this._info = null;
            this._nameTxtBmp = null;
            this._propBg = null;
            if (this._propItem) 
            {
                this._propItem.dispose();
                this._propItem = null;
            }
            return;
        }

        /* internal */ /* var */_expectionBmp: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_bg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_propBg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_investBtn: GButton;

        /* internal */ /* var */_propItem: BaseItem;

        /* internal */ /* var */_info: TInvestPlan;

        /* internal */ /* var */_nameTxtBmp: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_isLoaded: Boolean=false;

        /* internal */ /* var */_adTxt: GTextFiled;
    }
